/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.ipn.escuela.web;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import mx.ipn.escuela.dao.AlumnoDao;
import mx.ipn.escuela.modelo.Alumno;

/**
 *
 * @author jdmr
 */
@ManagedBean
@SessionScoped
public class AlumnoController {

    @EJB
    private AlumnoDao alumnoDao;
    private DataModel alumnos;
    private Alumno alumno;

    /** Creates a new instance of AlumnoController */
    public AlumnoController() {
    }

    public DataModel getAlumnos() {
        alumnos = new ListDataModel(alumnoDao.lista());
        return alumnos;
    }

    public String edita() {
        alumno = (Alumno) alumnos.getRowData();
        return "edita";
    }

    public Alumno getAlumno() {
        return alumno;
    }
    
    public String guarda() {
        alumno = alumnoDao.actualiza(alumno);
        return "lista";
    }

}
